import React, { Component } from 'react'
import MyNavBar from 'components/navbar';
import styles from './index.less'
import { List, WingBlank, Toast, Modal } from 'antd-mobile'
import router from 'umi/router';
import { connect } from 'dva'
import { ENTER_TYPE } from 'utils/Enum'
import { checkUrl,getIsDingTalk,backToOut } from 'utils/utils'
import commonStyles from 'utils/common.less';
import { recordEnterHistoryNum } from '../../utils/utils';
/**
 * @description 企业认证列表页面
 * @author 马羽
 * @date 2019-12-26
 * @class EnterpriseCertificationList
 * @extends {Component}
 */
@connect(({EnterpriseCertificationListModel}) => ({EnterpriseCertificationListModel}))
class EnterpriseCertificationList extends Component {
  state = {
    options: [
      {
        id:'EnterpriseCertification',
        name:'企业认证',
        desc:'申请人实名认证，提交企业信息在线核验，全程自动识别校验，认证审核零等待',
        url:'/EnterpriseCertificationListBackUps'
      }
    ]
  }
  async componentDidMount() {

    let { EnterpriseCertificationListModel } = this.props
    if(checkUrl(EnterpriseCertificationListModel)) {
      const isEnterPage=localStorage.getItem('isEnterPage')||'yes';
      if(isEnterPage==='yes'){
        recordEnterHistoryNum();
      }
     const Session=localStorage.getItem('Session')
      const url=localStorage.getItem('returnUrl')
      const enterType=localStorage.getItem('enterType')
      if(enterType === ENTER_TYPE.EXTERNAL) {
        // if(!localStorage.getItem('userWsid')) {
            //代表是外部跳转进来的
          //存储Session 和 url
          Toast.loading('查询中')
          let { dispatch } = this.props
          //去查询用户的wsid
          await dispatch({
            type: 'EnterpriseCertificationListModel/getUserWsid',
            payload: Session,
            callback: (state, wsid) => {
              if(state === 'error') {
                Toast.fail('未登录', 2, () => {
                  backToOut();
                })
              } else {
                localStorage.setItem('userWsid', wsid)
                Toast.hide()
              }

            }
          })
        }
      // }
    } else {
      if(localStorage.getItem("enterType")!==ENTER_TYPE.INTERIOR){
        const alert = Modal.alert
        alert('警告', '无法操作！', [
          { text: '返回', onPress: () => backToOut() },
        ])
      }

    }
  }
  goBack=()=>{
    const enterType=localStorage.getItem('enterType')
    let url=''
    if(enterType === ENTER_TYPE.EXTERNAL) {
      url=''
      return url
    }
    url='/Signature';
    return url
  }
  getIsExternal=()=>{
    const enterType=localStorage.getItem('enterType')
    let isExternal=false
    if(enterType === ENTER_TYPE.EXTERNAL) {
      isExternal=true
    }
    return isExternal
  }
  render() {

    const isExternal=this.getIsExternal()
    const isDingTalk=getIsDingTalk()
    let url =this.goBack()
    const { options } = this.state
    const Item = List.Item
    const Brief = Item.Brief

    // const contentContainer=commonStyles.headerTop
    const contentContainer=isDingTalk==='true'?'':commonStyles.headerTop
    return (
      <div className={styles.baseLayout}>
        <MyNavBar title={'选择企业认证方式'} backUrl={url} isExternal={isExternal}/>
        <WingBlank className='wingBlankBox' style={{paddingTop: '11%'}}>
          <List className={contentContainer}>
            {
              options.map(item => (
                <Item
                  align="middle"
                  key={item.id}
                  className={styles.item}
                  onClick={this.goListBackUps.bind(this, item.url)}
                  multipleLine
                >
                  {item.name}
                  <div className={styles.desc}>{item.desc}</div>
                </Item>
              ))
            }
          </List>
        </WingBlank>
      </div>
    )
  }

  //跳转到企业认证方式列表备份页面
  goListBackUps = (url) => {
    router.push(url)
  }
}

export default EnterpriseCertificationList
